package controller;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class realtime {
	public static void main(String[] args) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		ArrayList<String> arrayList = new ArrayList<String>();
		try {
			Document doc = Jsoup.connect("http://m.naver.com").get();
			String[] data = doc.getElementById("recommend_json").toString()
					.split("\n");
			FileWriter out = new FileWriter(
					"E:\\9.NHN SM\\1.workplace\\130523_final\\step10_realtimeInfo\\WebContent\\test01.json");
			for (String result : data) {
				if (result.contains("try")) {
					arrayList.add(result.split("=")[1].split("; }")[0]);
					System.out.println(result.split("=")[1].split("; }")[0]);
				}
			}
			JSONArray Jsonarray = JSONArray.fromObject(arrayList);
			map.put("alldata", Jsonarray);
			JSONObject jsonObject = JSONObject.fromObject(map);
			out.write(jsonObject.toString());
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
